<template>
    <div>
        <div class="app-container" v-if="showHome">
            <div class="top-box">
            <img src="@/assets/images/gzx.png" class="logo" />
            <span>模块管理</span>
            </div>
            <el-button type="primary" @click="openAddPmBus">添加新模块</el-button>
            <new-pm-bus ref="new_pm_bus" :cProNumList="cProNumList"
            :title="title" :user=user @queryPmBus="queryPmBus"
            ></new-pm-bus>
        <el-table
        height="500"
        :data="pmBusArray"
        border>
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="业务名称" align="center" prop="busNme" />
        <el-table-column label="用户名" align="left"  sortable>
            <template slot-scope="scope">
                <span>
                    {{cProNumList.find(x=>x.cProNo==scope.row.proNo)?cProNumList.find(x=>x.cProNo==scope.row.proNo).cProNme:''}}
                </span>
            </template>
        </el-table-column>
        <el-table-column label="模块功能介绍" align="center" prop="busBi" />
        <el-table-column label="接口" align="center" prop="busInterface" />
        <el-table-column label="SDK" align="center" prop="busSdk" />
        <el-table-column label="代码包" align="center" prop="busCodePackages" />
        <el-table-column label="业务模块详情" align="center" prop="busDet" />
        <el-table-column label="租户号" align="center" prop="tenantId" />
        <el-table-column label="乐观锁" align="center" prop="revision" />
        <el-table-column label="创建人" align="center" prop="createdBy" />
        <el-table-column label="创建时间" align="center" prop="createdTime" />
        <el-table-column label="更新人" align="center" prop="updatedBy" />
        <el-table-column label="更新时间" align="center" prop="updatedTime" />
        <el-table-column label="操作" align="center" header-align="left" class-name="small-padding fixed-width">
            <template slot-scope="scope">
                <div :style="{display:'flex',flexDirection:'column'}">
                    <el-popconfirm
                title="确定删除吗？"
                @confirm="handleDelete(scope.row, 'single')"
            >
                <el-button :style="{width:'50px'}"
                size="mini"
                slot="reference"
                >删除</el-button>
            </el-popconfirm>
            <el-button  :style="{width:'50px'}"
                size="mini"
                style="margin-left: 15px"
                @click="handleUpdate(scope.row)"
            >修改</el-button>
                </div>
            </template>
        </el-table-column>
        </el-table>
        </div>
        <div :style="{display:'flex',justifyContent:'flex-end'}">
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNumber"
            :page-sizes="[10, 15, 20, 30]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
            <div :style="{width:'50px'}"></div>
        </div>
    </div>
</template>

<script>
import { insertPmBus,pmBusList,pmBusTest,deletePmBus } from "@/api/projectManage/pmbus";
import { mapGetters, mapState } from "vuex";
import newPmBus from './newPmBus.vue';
import {deleteProkect, emitList, list as pmProList, listNum, listWorkNum} from "@/api/projectManage/project";
import store from '@/store/index'
    export default {
        components: { newPmBus },
        data(){
            return{
                showHome: true,
                cProNumList:[],
                title:'',
                user:null,
                pageNumber:1,
                pageSize:10,
                total:0,
                pmBusArray:[]
            }
        },
        methods:{
            //打开对话框添加模块
            openAddPmBus(){

                this.title='添加模块'
                this.$refs.new_pm_bus.open()
            },
            //打开对话框修改模块
            handleUpdate(row){
                this.title='修改模块'
                this.$refs.new_pm_bus.updatePmBus(row)
                this.$refs.new_pm_bus.openUpdate()
            },
            //查询
            queryPmBus(){
                pmBusList(this.pageNumber,this.pageSize).then(resp=>{
                    this.pmBusArray=resp.data.pmBusList
                    this.total=resp.data.total
                })
            },
            //删除
            handleDelete(pmBus,b){
                deletePmBus(pmBus.busNo).then(resp=>{
                    if(resp.code==200){
                        this.queryPmBus()
                    }
                })
            },
            //每页记录数发生变动
            handleSizeChange(pageSize){
                this.pageSize=pageSize
                this.pageNumber=1
                this.queryPmBus()
            },
            //本页数发生变动
            handleCurrentChange(pageNumber){
                this.pageNumber=pageNumber
                this.queryPmBus()
            }
        },
        created(){
            this.queryPmBus()
            this.user=store._modules.root.state.user
            pmProList().then(resp=>{
                pmProList({pageSize:resp.total}).then(re=>{
                    this.cProNumList=re.rows  // .map({cProNo,cProNme})
                })
            })
        }
    }
</script>

<style lang="scss" scoped>
@import "@/assets/styles/projectManage";
</style>
